package a10_动态规划;

import java.util.Scanner;

/**
 * <p>
 * a18_完全背包理论基础复习4
 * </p>
 *
 * @author flyduck
 * @since 2025/4/14
 */
public class a18_完全背包理论基础复习4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int num = scanner.nextInt();
        int totalWeight = scanner.nextInt();

        int[] weight = new int[num];
        int[] value = new int[num];

        for (int i = 0; i < num; i++) {
            weight[i] = scanner.nextInt();
            value[i] = scanner.nextInt();
        }

        //dp[i][j]：0~i的物品装满容量为j的背包的最大价值

        //递推公式：
        //不包含i：dp[i-1][j]
        //包含i：dp[i][j-weight[i]] + value[i]


        int[] dp = new int[totalWeight+1];
        for (int i = 0; i < weight.length; i++) {
            for (int j = weight[i]; j <= totalWeight; j++) {
                dp[j] = Math.max(dp[j],dp[j-weight[i]] + value[i]);
            }
        }

        System.out.println(dp[totalWeight]);
    }
}
